package com.yr.service;

import com.yr.common.Constant;
import com.yr.common.util.FileUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import java.time.LocalDate;
import java.util.UUID;

/**
 * Created by gx on 2017/6/9.
 */
@Service
public class FileService {
    public void upload(MultipartHttpServletRequest file) throws Exception {
        MultiValueMap<String, MultipartFile> map = file.getMultiFileMap();
        String fileName = map.getFirst("file").getOriginalFilename();
//        String fileExtensionName = fileName.substring(fileName.lastIndexOf(".")+1);
        String localDate = LocalDate.now().toString();
//        String uploadFileName = UUID.randomUUID().toString()+"."+fileExtensionName;
        String path = Constant.getRootPath()+localDate+"/"+fileName;
        FileUtil.uploadFile(map.getFirst("file").getInputStream(),path);
    }
}
